package com.ruoqing.blog.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.ruoqing.blog.service.api.RecommendService;
import com.ruoqing.blog.service.impl.BlogServiceImpl;
import com.ruoqing.core.dto.BaseResponse;
import com.ruoqing.core.dto.blog.BlogPageDto;
import com.ruoqing.core.vo.blog.BlogDetailsVo;
import com.ruoqing.core.vo.blog.BlogResponseVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
	* @author YaoXian
	* @title: BlogRestApi
	* @projectName ruoxi-blog
	* @description: 若兮微服务 - 首页推荐博客 - 控制层接口
	* @date 2021-01-20 13:00
	*/
@RestController
@RequestMapping(path = "/blog")
public class BlogRestApi {
		
		@Resource
		private BlogServiceImpl blogService;
		
		@Resource
		private RecommendService recommendService;
		
		/**
			*  分页查询博客介绍接口
			* @param currentPage 当前页
			* @param pageSize 每页显示条数
			* @return R<BlogPageDto> 分页数据交换对象
			*/
		@GetMapping(path = "/introduce")
		public R<BlogPageDto> showBlogPage(Integer currentPage, Integer pageSize){
				return R.ok(blogService.selectBlogByPage(currentPage, pageSize));
		}
		
		/**
			*  展示推荐博客接口
			* @param type 推荐类型
			* @return BlogResponseVo 博客响应交换对象
			*/
		@GetMapping(path = "/recommend/{type}")
		public BlogResponseVo showRecommendBlog(@PathVariable String type){
				return recommendService.recommendBlog(type);
		}
		
		/**
			* 展示博客详情
			* @param blogId 博客Id编号
			* @return BlogDetailsVo 博客详情响应交换对象
			*/
		@GetMapping(path = "/details/{blogId}")
		public BlogDetailsVo showBlogDetails(@PathVariable Integer blogId) {
				return blogService.showDetailsById(blogId);
		}
		
		/**
			* 点赞或踩博客
			* 权限控制接口,需要鉴权是否登录
			* @param blogId 博客Id编号
			* @param type 操作类型
			* @return BaseResponse 基础响应交换对象
			*/
		@PreAuthorize(value = "isAuthenticated()")
		@PutMapping(path = "/thumb/{type}")
		public BaseResponse thumbBlog(Integer blogId,@PathVariable String type){
				return blogService.thumbBlogById(blogId,type);
		}
}
